package com.wenyu.wenyuyuedu.adapter.personage;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.bean.personage.IncomeDetailBean;
import com.wenyu.wenyuyuedu.utils.TimeFormat;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/17.
 * 提现的展示
 */

public class InComeAdapter extends BaseAdapter {
    private List<IncomeDetailBean.InfoBean> info = new ArrayList<>();
    private Context context;

    public InComeAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return info.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyInComeHolder holder = null;
        if (view == null) {
            holder = new MyInComeHolder();
            view = View.inflate(context, R.layout.income_item, null);
            holder.income_time = (TextView) view.findViewById(R.id.income_time);
            holder.tv_income_type = (TextView) view.findViewById(R.id.tv_income_type);
            holder.tv_income_money = (TextView) view.findViewById(R.id.tv_income_money);
            holder.income_money_type = (TextView) view.findViewById(R.id.income_money_type);
            view.setTag(holder);
        } else {
            holder = (MyInComeHolder) view.getTag();
        }
        String money = info.get(i).getMoney();
        int moneyInt = Integer.parseInt(money);
        int abs = Math.abs(moneyInt);
        double moneyType = (double) abs / 100;
        if (moneyInt < 0) {
            //时间
            String pubtime = info.get(i).getPubtime();
            long aLong = Long.valueOf(pubtime) * 1000;
            String dateToHHMMSS = TimeFormat.getDateToHHMMSS(aLong);
            holder.income_time.setText(dateToHHMMSS);
            //收支的类型
            holder.tv_income_type.setText("提现");
            //获取类型
            String type = info.get(i).getType();
            int typeInt = Integer.parseInt(type);
            if (typeInt == 0) {
                //收支的钱数
                holder.tv_income_money.setTextColor(Color.parseColor("#FD982B"));
                holder.tv_income_money.setText("- ￥" + moneyType);
                holder.income_money_type.setText("正在审核中");
                holder.income_money_type.setTextColor(Color.parseColor("#FD982B"));
            } else if (typeInt == 1) {
                holder.tv_income_money.setTextColor(Color.parseColor("#FD982B"));
                holder.tv_income_money.setText("- ￥" + moneyType);
                holder.income_money_type.setText("审核通过，正在打款中");
                holder.income_money_type.setTextColor(Color.parseColor("#FD982B"));
            } else if (typeInt == 2) {
                holder.tv_income_money.setTextColor(Color.parseColor("#FD982B"));
                holder.tv_income_money.setText("- ￥" + moneyType);
                holder.income_money_type.setText("已完成");
                holder.income_money_type.setTextColor(Color.parseColor("#FD982B"));
            }
        } else if (moneyInt > 0) {
            //时间
            String pubtime = info.get(i).getPubtime();
            long aLong = Long.valueOf(pubtime) * 1000;
            String dateToHHMMSS = TimeFormat.getDateToHHMMSS(aLong);
            holder.income_time.setText(dateToHHMMSS);
            //收支的类型
            holder.tv_income_type.setText("收到了打赏");
            //收支的钱数
            holder.tv_income_money.setText("+ ￥" + moneyType);
            //收支的状态
            holder.income_money_type.setText("已完成");
        }
        return view;
    }

    class MyInComeHolder {
        TextView income_time, tv_income_type, tv_income_money, income_money_type;

    }

    public void addAll(List<IncomeDetailBean.InfoBean> info) {
        if (info != null) {
            this.info = info;
            notifyDataSetChanged();
        }
    }
}
